package com.ruoyi.user.controller;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.servlet.http.HttpServletResponse;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.redis.RedisUtil;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.huanxing.EMServiceUtil;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.date.DateUtils;
import com.ruoyi.common.utils.parameter.SystemPushText;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.PriceSetting;
import com.ruoyi.system.domain.RegularMsgSend;
import com.ruoyi.system.domain.UserSystemMsg;
import com.ruoyi.system.mapper.PriceSettingMapper;
import com.ruoyi.system.mapper.RegularMsgSendMapper;
import com.ruoyi.system.service.IUserSystemMsgService;
import com.ruoyi.thread.TaskAsync;
import com.ruoyi.user.domain.CustomerConfig;
import com.ruoyi.user.domain.User;
import com.ruoyi.user.domain.UserCapitalFlow;
import com.ruoyi.user.domain.UserExtend;
import com.ruoyi.user.domain.UserTotalCapital;
import com.ruoyi.user.mapper.CustomerConfigMapper;
import com.ruoyi.user.mapper.UserCapitalFlowMapper;
import com.ruoyi.user.mapper.UserExtendMapper;
import com.ruoyi.user.mapper.UserTotalCapitalMapper;
import com.ruoyi.user.pojo.AppUserDetail;
import com.ruoyi.user.service.IUserService;
import com.ruoyi.user.service.IUserTotalCapitalService;

import cn.hutool.core.collection.CollectionUtil;

/**
 * 用户Controller
 * 
 * @author DEREK
 * @date 2023-05-10
 */
@RestController
@RequestMapping("/user/user")
public class UserController extends BaseController
{
	@Autowired
	private IUserService userService;
	@Autowired
	private UserTotalCapitalMapper userTotalCapitalMapper;
	@Autowired
	private IUserTotalCapitalService userTotalCapitalService;
	@Autowired
	private IUserSystemMsgService userSystemMsgService;
	@Autowired
	private UserCapitalFlowMapper userCapitalFlowMapper;
	@Autowired
	private RedisUtil redisUtil;
	@Autowired
	private UserExtendMapper userExtendMapper;
	@Autowired
	private RegularMsgSendMapper regularMsgSendMapper;
	@Autowired
	private TaskAsync taskAsync;
	@Autowired
	private PriceSettingMapper priceSettingMapper;
	@Autowired
	private CustomerConfigMapper customerConfigMapper;


	/**
	 * 	添加获取参数
	 * @return
	 */
	 @PreAuthorize("@ss.hasPermi('user:user:list')")
	 @GetMapping(value = "/qrySaveData")
	 public AjaxResult qrySaveData()  {
		 Map<String,Object> map = new HashMap<String, Object>();
		 List<AppUserDetail> sendUserList = userService.getSendUserList();
		 map.put("sendUserList", sendUserList);
		 return AjaxResult.success(map);
	 }

	 /**
	  * 	获取聊天记录下载地址
	  * @param date
	  * @return
	  */
	 @PreAuthorize("@ss.hasPermi('user:user:list')")
	 @GetMapping("/getDownloadUrl")
	 public AjaxResult getDownloadUrl(String date){
		 try {
			 if(StringUtils.isEmpty(date)) {
				 return AjaxResult.error("请选择日期");
			 }
			 String url = "https://a1.easemob.com/1151230809175214/demo/chatmessages/"+date;
			 RequestConfig config = RequestConfig.custom().setConnectTimeout(60000).setSocketTimeout(15000).build();
			 HttpClient httpClient = HttpClientBuilder.create().setDefaultRequestConfig(config).build();
			 HttpGet httpget = new HttpGet(url);
			 httpget.addHeader("Accept","application/json");
			 httpget.addHeader("Authorization","Bearer YWMt-1ausHJLEe6C0eeaOhqstpPaTfaxrjFvim9cX9VmPio9qcpjmD1G-ax5qJAbq82LAgMAAAGLYOtPmTeeSAABld7sAiUix_s27elX8l4LqVyT7yRIbZLVTWffVBs_uQ");
			 HttpResponse execute = httpClient.execute(httpget);
			 String result = EntityUtils.toString(execute.getEntity(),"UTF-8");
			 System.out.println(result);
			 if(result.contains("error")) {
				 return AjaxResult.error("当前时间段不存在聊天记录或已被清理");
			 }
			 JSONObject parseObject = JSONObject.parseObject(result);
			 JSONObject jsonObject = parseObject.getJSONArray("data").getJSONObject(0);
			 String downloadUrl = jsonObject.getString("url");
			 if(StringUtils.isEmpty(downloadUrl)) {
				 return AjaxResult.error("当前时间段不存在聊天记录或已被清理");
			 }
			 return AjaxResult.success("获取成功",downloadUrl);
		 } catch (Exception e) {
			 e.printStackTrace();
			 return AjaxResult.error(e.getMessage());
		 }

	 }

	 /**
	  * 	查询用户列表
	  */
	 @PreAuthorize("@ss.hasPermi('user:user:list')")
	 @GetMapping("/list")
	 public TableDataInfo list(User user)
	 {
		 startPage();
		 if(1 == user.getManageType()) {
			 user.setManageId(getUserId());
		 }
		 if(null != user.getWeekType() && 8 == user.getWeekType()) {
			 user.setWeekStr("1,2,3,4,5,6,7");
			 user.setWeekType(null);
		 }
		 List<User> list = userService.selectUserList(user);
		 list.stream().forEach(u ->{
			 // 用户余额
			 String amountByUserId = userTotalCapitalMapper.getAmountByUserId(u.getId());
			 if(StringUtils.isNotEmpty(amountByUserId)) {
				 u.setTotalAmount(new BigDecimal(amountByUserId));
			 }
			 // 收益余额
			 UserTotalCapital initData = userTotalCapitalService.initData("1", u.getId());
			 u.setIncomeAmount(initData.getTotalAmount());
			 u.setWaitAmount(initData.getWaitAmount());
			 u.setCanAmount((initData.getCanAmount().subtract(initData.getFrozenAmount())));
			 // 环信ID返回
			 UserExtend extend = userExtendMapper.selectOne(new LambdaQueryWrapper<UserExtend>().eq(UserExtend::getUserId, u.getId()));
			 if(null != extend && StringUtils.isNotEmpty(extend.getEmUsername())) {
				 u.setEmUsername(extend.getEmUsername());
			 }
			 // 转换登录时间
			 if(null != u.getLoginTime()) {
				 if(3 != u.getEnabled()) {
					 u.setVirtuallyStatus(DateUtils.getLoginTimeHome(u.getLoginTime()));
				 }
			 }
		 });
		 return getDataTable(list);
	 }

	 /**
	  * 导出用户列表
	  */
	 @PreAuthorize("@ss.hasPermi('user:user:export')")
	 @Log(title = "用户", businessType = BusinessType.EXPORT)
	 @PostMapping("/export")
	 public void export(HttpServletResponse response, User user)
	 {
		 List<User> list = userService.selectUserList(user);
		 ExcelUtil<User> util = new ExcelUtil<User>(User.class);
		 util.exportExcel(response, list, "用户数据");
	 }

	 /**
	  * 获取用户详细信息
	  */
	 @PreAuthorize("@ss.hasPermi('user:user:query')")
	 @GetMapping(value = "/{id}")
	 public AjaxResult getInfo(@PathVariable("id") Long id)
	 {
		 User user = userService.getById(id);
		 if(null != user) {
			 //    		String amountByUserId = userTotalCapitalMapper.getAmountByUserId(3, id);
			 //        	if(StringUtils.isNotEmpty(amountByUserId)) {
			 //        		user.setTotalAmount(new BigDecimal(amountByUserId));
			 //        	}
			 //        	// 收益余额
			 //        	String incomeAmount = userTotalCapitalMapper.getAmountByUserId(1, user.getId());
			 //        	if(StringUtils.isNotEmpty(incomeAmount)) {
			 //        		user.setIncomeAmount(new BigDecimal(incomeAmount));
			 //        	}
		 }
		 return AjaxResult.success(user);
	 }

	 /**
	  * 新增用户
	  */
	 @PreAuthorize("@ss.hasPermi('user:user:add')")
	 @Log(title = "用户", businessType = BusinessType.INSERT)
	 @PostMapping
	 public AjaxResult add(@RequestBody User user)
	 {
		 return toAjax(userService.save(user));
	 }

	 /**
	  * 修改用户
	  */
	 @PreAuthorize("@ss.hasPermi('user:user:edit')")
	 @Log(title = "用户", businessType = BusinessType.UPDATE)
	 @PutMapping
	 public AjaxResult edit(@RequestBody User user)
	 {
		 User one = userService.getOne(new LambdaQueryWrapper<User>().eq(User::getId, user.getId()).select(User::getId,User::getVip,User::getVipLevel));
		 //    	if(null != one && 0 == one.getVip() && 1 == user.getVip()) {
		 //    		Object object = redisUtil.get(ProjectConstant.platformConstant.UNLOCKWECHATCOUNT);
		 //			if(null != object) {
		 //				user.setUnlockWechat(Integer.valueOf(object.toString()));
		 //			}
		 //			Object object2 = redisUtil.get(ProjectConstant.platformConstant.UNLOCKCHATCOUNT);
		 //			if(null != object2) {
		 //				user.setChatCount(Integer.valueOf(object2.toString()));
		 //			}

		 //    	}
		 // 判断是否为新VIP 或者是升级VIP
		 if((0 == one.getVip() && 1 == user.getVip()) || (1 == one.getVip() && user.getVipLevel() > one.getVipLevel())) {
			 PriceSetting set = priceSettingMapper.selectOne(new LambdaQueryWrapper<PriceSetting>()
					 .eq(PriceSetting::getAmountType, 1).eq(PriceSetting::getExtend4, user.getVipLevel()).last("limit 1"));
			 if(set != null ) {
				user.setUnlockWechat(Integer.valueOf(set.getExtend2()));
				user.setChatCount(Integer.valueOf(set.getExtend3()));
			 }
		 }
		 boolean updateById = userService.updateById(user);
		 return toAjax(updateById);
	 }

	 /**
	  * 	修改用户余额
	  * @param user		用户
	  */
	 public void updateTotalAmount(User user) {
		 UserTotalCapital userTotalCapital = userTotalCapitalService.initData("3", user.getId());
		 String remark = StringUtils.isEmpty(user.getRemark())?"后台管理员修改余额":user.getRemark();

		 if(null != userTotalCapital) {
			 BigDecimal totalAmount = userTotalCapital.getTotalAmount().subtract(userTotalCapital.getFrozenAmount());
			 UserCapitalFlow flow = new UserCapitalFlow();
			 flow.setType(7);
			 flow.setAmount(user.getTotalAmount());
			 flow.setUserId(user.getId());
			 flow.setRemark(remark);
			 if(1 == user.getEnabled()) { // 增加余额
				 userTotalCapital.setTotalAmount(userTotalCapital.getTotalAmount().add(user.getTotalAmount()));
				 userTotalCapitalMapper.updateById(userTotalCapital);
				 flow.setBusinessType(12);
				 flow.setNameType("改动前余额:"+totalAmount+",改动后余额:"+userTotalCapital.getTotalAmount());
				 userCapitalFlowMapper.insert(flow);
			 }else if(2 == user.getEnabled()) {// 减少余额
				 userTotalCapital.setTotalAmount(userTotalCapital.getTotalAmount().subtract(user.getTotalAmount()));
				 userTotalCapitalMapper.updateById(userTotalCapital);
				 flow.setBusinessType(13);
				 flow.setNameType("改动前余额:"+totalAmount+",改动后余额:"+userTotalCapital.getTotalAmount());
				 userCapitalFlowMapper.insert(flow);
			 }
		 }
		 if(StringUtils.isNotEmpty(user.getRemark())) {
			 UserSystemMsg userSystemMsg = new UserSystemMsg();
			 userSystemMsg.setUserId(user.getId());
			 userSystemMsg.setTitle("管理员修改余额");
			 userSystemMsg.setContent("后台管理员修改余额："+remark);
			 userSystemMsg.setIcon(SystemPushText.BDAppPushIcon.SYSTEM_ICON);
			 userSystemMsgService.save(userSystemMsg);
		 }
	 }

	 /**
	  * 	修改用户收益
	  * @param user		用户
	  */
	 public void updateIncomeAmount(User user) {
		 UserTotalCapital userTotalCapital = userTotalCapitalService.initData("1", user.getId());

		 String remark = StringUtils.isEmpty(user.getRemark())?"后台管理员修改收益余额":user.getRemark();
		 if(null != userTotalCapital) {
			 BigDecimal totalAmount = userTotalCapital.getTotalAmount().subtract(userTotalCapital.getFrozenAmount());
			 UserCapitalFlow flow = new UserCapitalFlow();
			 flow.setType(8);
			 flow.setAmount(user.getTotalAmount());
			 flow.setUserId(user.getId());
			 flow.setRemark(remark);
			 String key = com.ruoyi.common.utils.date.DateUtils.dateToString(new Date(), "yyyyMM")+"-"+user.getId();
			 if(user.getTotalAmount().compareTo(totalAmount) == 1) { // 增加余额
				 userTotalCapital.setTotalAmount(userTotalCapital.getTotalAmount().add(user.getTotalAmount()));
				 userTotalCapital.setWaitAmount(userTotalCapital.getWaitAmount().add(user.getTotalAmount()));
				 redisUtil.set(key, userTotalCapital.getWaitAmount());
				 userTotalCapitalMapper.updateById(userTotalCapital);
				 flow.setNameType("改动前收益余额:"+totalAmount+",改动吼收益余额:"+userTotalCapital.getTotalAmount());
				 flow.setBusinessType(14);
				 userCapitalFlowMapper.insert(flow);
			 }else if(user.getTotalAmount().compareTo(totalAmount) == -1) {// 减少余额
				 userTotalCapital.setTotalAmount(userTotalCapital.getTotalAmount().subtract(user.getTotalAmount()));
				 userTotalCapital.setWaitAmount(userTotalCapital.getWaitAmount().subtract(user.getTotalAmount()));
				 redisUtil.set(key, userTotalCapital.getWaitAmount());
				 userTotalCapitalMapper.updateById(userTotalCapital);
				 flow.setBusinessType(15);
				 flow.setNameType("改动前收益余额:"+totalAmount+",改动吼收益余额:"+userTotalCapital.getTotalAmount());
				 userCapitalFlowMapper.insert(flow);
			 }
		 }
		 if(StringUtils.isNotEmpty(user.getRemark())) {
			 UserSystemMsg userSystemMsg = new UserSystemMsg();
			 userSystemMsg.setUserId(user.getId());
			 userSystemMsg.setTitle("管理员修改收益余额");
			 userSystemMsg.setContent("后台管理员修改收益余额："+remark);
			 userSystemMsg.setIcon(SystemPushText.BDAppPushIcon.SYSTEM_ICON);
			 userSystemMsgService.save(userSystemMsg);
		 }
	 }

	 /**
	  * 删除用户
	  */
	 @PreAuthorize("@ss.hasPermi('user:user:remove')")
	 @Log(title = "用户", businessType = BusinessType.DELETE)
	 @DeleteMapping("/{ids}")
	 public AjaxResult remove(@PathVariable Long[] ids)
	 {
		 return toAjax(userService.deleteUserByIds(ids));
	 }

	 @PreAuthorize("@ss.hasPermi('user:user:edit')")
	 @Log(title = "将用户加入推送列表", businessType = BusinessType.UPDATE)
	 @GetMapping("/joinMsgSend")
	 public AjaxResult joinMsgSend(Long id)
	 {

		 RegularMsgSend one = regularMsgSendMapper.selectOne(new LambdaQueryWrapper<RegularMsgSend>().eq(RegularMsgSend::getUserId, id).last("limit 1"));
		 if(null != one) {
			 return AjaxResult.error("此用户已加入推送列表");
		 }
		 // regularMsgSendMapper
		 AppUserDetail userDetail = new AppUserDetail();
		 userDetail.setUserId(id);
		 userDetail.setType(1);
		 List<AppUserDetail> userBasicInfo = userService.getUserBasicInfo(userDetail);
		 if(CollectionUtil.isEmpty(userBasicInfo)) {
			 return AjaxResult.error("用户不存在");
		 }
		 userDetail = userBasicInfo.get(0);

		 RegularMsgSend regular = new RegularMsgSend();
		 regular.setUserId(id);
		 regular.setNickName(userDetail.getNickName());
		 regular.setEmUsername(userDetail.getEmUsername());
		 regular.setTimeDay(0);
		 regular.setTimeHour(0);
		 regular.setTimeMinute(0);
		 regular.setTimeSecond(0);
		 regular.setIsEnabled(0);
		 regular.setCreateTime(new Date());
		 regular.setSex(userDetail.getSex());
		 regularMsgSendMapper.insert(regular);
		 return AjaxResult.success(); 
	 }
	 
	 @PreAuthorize("@ss.hasPermi('user:user:join')")
	 @Log(title = "将用户加入当前登录账户旗下", businessType = BusinessType.UPDATE)
	 @GetMapping("/joinManage")
	 public AjaxResult joinManage(Long id)
	 {
		 User user = userService.getOne(new LambdaQueryWrapper<User>().eq(User::getId, id).select(User::getId,User::getManageId,User::getManageName));
		 if(user.getManageId() > 0) {
			 return AjaxResult.error("当前用户已经加入 "+user.getManageName()+" 旗下");
		 }
		 user.setManageId(getUserId());
		 user.setManageName(getUsername());
		 userService.updateById(user);
		 return AjaxResult.success("加入成功");
		  
	 }
	 
	 @PreAuthorize("@ss.hasPermi('user:user:customer')")
	 @Log(title = "将用户加入客服", businessType = BusinessType.UPDATE)
	 @GetMapping("/joinCustomer")
	 @Transactional
	 public AjaxResult joinCustomer(Long id)
	 {
		 User user = userService.getOne(new LambdaQueryWrapper<User>().eq(User::getId, id).select(User::getId,User::getIsCustomer));
		 if(user.getIsCustomer() > 0) {
			 return AjaxResult.error("当前用户已经是客服");
		 }
		 Integer count = customerConfigMapper.selectCount(null);
		 if(count > 0) {
			 return AjaxResult.error("已存在客服,请先删除");
		 }
		 user.setIsCustomer(1);
		 userService.updateById(user);
		 CustomerConfig config = new CustomerConfig();
		 config.setUserId(id);
		 config.setBegTime("09:00");
		 config.setEndTime("17:30");
		 config.setWeek("1,2,3,4,5");
		 config.setContent("当前客服人员不在线，上班时间为周一至周五早09:00-晚17:30");
		 customerConfigMapper.insert(config);
		 return AjaxResult.success("加入成功");
		  
	 }
	 
	 
	 @PreAuthorize("@ss.hasPermi('user:user:remove')")
	 @Log(title = "将用户移除当前账号", businessType = BusinessType.UPDATE)
	 @GetMapping("/handleDelUser")
	 public AjaxResult handleDelUser(Long id)
	 {
		 User user = userService.getOne(new LambdaQueryWrapper<User>().eq(User::getId, id).select(User::getId,User::getManageId,User::getManageName));
		 user.setManageId(0L);
		 user.setManageName("");
		 userService.updateById(user);
		 return AjaxResult.success("移除成功");
		  
	 }

	 @PreAuthorize("@ss.hasPermi('user:user:edit')")
	 @Log(title = "更新用户详细地址", businessType = BusinessType.UPDATE)
	 @GetMapping("/updAddress")
	 public AjaxResult updAddress(Long id)
	 {
		 User user = userService.getOne(new LambdaQueryWrapper<User>().eq(User::getId, id).select(User::getId,User::getLoginPointX,User::getLoginPointY));
		 if(null == user) {
			 return AjaxResult.error("用户不存在");
		 }
		 if(null == user.getLoginPointX() || null == user.getLoginPointY()) {
			 return AjaxResult.error("该用户未开启定位");
		 }
		 taskAsync.updUserDetailedAddress(id, user.getLoginPointX(), user.getLoginPointY());
		 return AjaxResult.success();
	 }

	 @PreAuthorize("@ss.hasPermi('user:user:edit')")
	 @Log(title = "修改用户余额", businessType = BusinessType.UPDATE)
	 @PostMapping("/updateUserAmount")
	 public AjaxResult updateUserAmount(@RequestBody User user)
	 {
		 // vip  1=余额 2=收益  enabled 1=增加 2=减少  totalAmount = 总金额  remark = 备注
		 // 余额是否改动
		 if(null != user.getTotalAmount() && user.getTotalAmount().compareTo(BigDecimal.ZERO) == 1) {
			 if(1 == user.getVip()) {
				 updateTotalAmount(user);
			 }else {
				 updateIncomeAmount(user);
			 }
		 }
		 return AjaxResult.success();
	 }

	 @Autowired
	 private EMServiceUtil eMServiceUtil;

	 @PreAuthorize("@ss.hasPermi('user:user:edit')")
	 @Log(title = "发送消息", businessType = BusinessType.UPDATE)
	 @PostMapping("/sendUserMsg")
	 public AjaxResult sendUserMsg(@RequestBody AppUserDetail appUserDetail)
	 {
		 // {"concernStatus":0,"favorableRate":"0%","id":133,"isBack":0,"isBindWechat":0,"isWehcat":0,"linkMicrophone":"无",
		 // "orderCount":0,"photoList":[],"remark":"1","type":0,"userId":1}
		 if(null == appUserDetail || null == appUserDetail.getId() || null == appUserDetail.getUserId() || StringUtils.isEmpty(appUserDetail.getRemark())) {
			 return AjaxResult.error("参数为空");
		 }
		 AppUserDetail form = new AppUserDetail();
		 form.setType(1);
		 form.setUserId(appUserDetail.getUserId());
		 List<AppUserDetail> userBasicInfo = userService.getUserBasicInfo(form);
		 if(CollectionUtil.isEmpty(userBasicInfo)) {
			 return AjaxResult.error("参数为空");
		 }
		 form = userBasicInfo.get(0);
		 AppUserDetail toU = new AppUserDetail();
		 toU.setType(1);
		 toU.setUserId(appUserDetail.getId());
		 List<AppUserDetail> toUserBasicInfo = userService.getUserBasicInfo(toU);
		 if(CollectionUtil.isEmpty(toUserBasicInfo)) {
			 return AjaxResult.error("参数为空");
		 }
		 toU = toUserBasicInfo.get(0);
		 Map<String,Object> map = new HashMap<String,Object>();
		 map.put("myHeadPic", form.getHeadPic());
		 map.put("myName", form.getEmUsername());
		 map.put("myName_custom", form.getNickName());
		 map.put("userId_my", form.getUserId());
		 map.put("userId_your", toU.getUserId());
		 map.put("your", toU.getEmUsername());
		 map.put("yourHeadPic", toU.getHeadPic());
		 map.put("your_custom", toU.getNickName());
		 Set<String> setIds = new HashSet<String>();
		 setIds.add(toU.getEmUsername());
		 eMServiceUtil.sendSystemMsg(form.getEmUsername(), appUserDetail.getRemark(), setIds, map);
		 return AjaxResult.success();
	 }
	 
	 /**
	  * 	加入或者删除当前星期几
	  * @param id		用户ID
	  * @param week		星期几 1-7
	  * @param type		1=加入 2=删除
	  * @return
	  */
	 @PreAuthorize("@ss.hasPermi('user:user:edit')")
	 @Log(title = "将用户加入某个星期几中", businessType = BusinessType.UPDATE)
	 @GetMapping("/addUserWeek")
	 public AjaxResult addUserWeek(Long id,Integer week,Integer type)
	 {
		 User user = new User();
		 user.setId(id);
		 if(1 == type) {
			 if(week <= 0) {
				 return AjaxResult.error("请选择星期");
			 }
			 user.setWeekType(week);
		 }else {
			 user.setWeekType(0);
		 }
		 userService.updateById(user);
		 return AjaxResult.success();
	 }

}
